From f111685c5886f3e77edfd3621c98d8ac1b9bcce4 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Fri, 24 Nov 2023 20:00:08 +0100
Subject: refactor(services, types): reorganize GraphQL fetchers and data types

The Typescript mapped types was useful for autocompletion in fetchers
but their are harder to maintain. I think it's better to keep each
query close to its fetcher to have a better understanding of the
fetched data. So I:
* colocate queries with their own fetcher
* colocate mutations with their own mutator
* remove Typescript mapped types for queries and mutations
* move data convertors inside graphql services
* rename most of data types and fetchers
---
 src/pages/sujet/[slug].tsx | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

(limited to 'src/pages/sujet/[slug].tsx')

diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx
index 30adec3..aed7ea9 100644
--- a/src/pages/sujet/[slug].tsx
+++ b/src/pages/sujet/[slug].tsx
@@ -18,10 +18,11 @@ import {
   PageBody,
 } from '../../components';
 import {
-  getAllTopicsSlugs,
-  getTopicBySlug,
-  getTopicsPreview,
-  getTotalTopics,
+  convertTaxonomyToPageLink,
+  fetchAllTopicsSlugs,
+  fetchTopic,
+  fetchTopicsCount,
+  fetchTopicsList,
 } from '../../services/graphql';
 import styles from '../../styles/pages/blog.module.scss';
 import type { NextPageWithLayout, PageLink, Topic } from '../../types';
@@ -29,7 +30,6 @@ import { CONFIG } from '../../utils/config';
 import { ROUTES } from '../../utils/constants';
 import {
   getLinksItemData,
-  getPageLinkFromRawData,
   getPostsWithUrl,
   getSchemaJson,
   getSinglePageSchema,
@@ -208,13 +208,13 @@ export const getStaticProps: GetStaticProps<TopicPageProps> = async ({
   locale,
   params,
 }) => {
-  const currentTopic = await getTopicBySlug((params as TopicParams).slug);
-  const totalTopics = await getTotalTopics();
-  const allTopicsEdges = await getTopicsPreview({
+  const currentTopic = await fetchTopic((params as TopicParams).slug);
+  const totalTopics = await fetchTopicsCount();
+  const allTopicsEdges = await fetchTopicsList({
     first: totalTopics,
   });
   const allTopics = allTopicsEdges.edges.map((edge) =>
-    getPageLinkFromRawData(edge.node, 'topic')
+    convertTaxonomyToPageLink(edge.node)
   );
   const topicsLinks = allTopics.filter(
     (topic) => topic.url !== `${ROUTES.TOPICS}/${(params as TopicParams).slug}`
@@ -231,7 +231,7 @@ export const getStaticProps: GetStaticProps<TopicPageProps> = async ({
 };
 
 export const getStaticPaths: GetStaticPaths = async () => {
-  const slugs = await getAllTopicsSlugs();
+  const slugs = await fetchAllTopicsSlugs();
   const paths = slugs.map((slug) => {
     return { params: { slug } };
   });
-- 
cgit v1.2.3

